package com.wao.product.domain;

import com.wao.base.domain.BaseMultitenantAuditingEntity;
import io.swagger.annotations.ApiModel;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Objects;

/**
 * Attribute entity.
 *
 * @author Arthur.
 */
@ApiModel(description = "Attribute entity. @author Arthur.")
@Entity
@Table(name = "product_attribute")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Attribute extends BaseMultitenantAuditingEntity {

    private static final long serialVersionUID = 1L;

    @NotNull
    @Column(name = "sku_pro", nullable = false)
    private Boolean skuPro;

    @Column(name = "display_order")
    private Integer displayOrder;

    @Size(max = 8)
    @Column(name = "lang_key", length = 8)
    private String langKey;

    @ManyToOne
    private Product product;

    @ManyToOne
    private ProductSku productSku;

    @ManyToOne(optional = false)
    @NotNull
    private Property property;

    @ManyToOne(optional = false)
    @NotNull
    private Value value;

    public Boolean isSkuPro() {
        return skuPro;
    }

    public Attribute skuPro(Boolean skuPro) {
        this.skuPro = skuPro;
        return this;
    }

    public void setSkuPro(Boolean skuPro) {
        this.skuPro = skuPro;
    }

    public Integer getDisplayOrder() {
        return displayOrder;
    }

    public Attribute displayOrder(Integer displayOrder) {
        this.displayOrder = displayOrder;
        return this;
    }

    public void setDisplayOrder(Integer displayOrder) {
        this.displayOrder = displayOrder;
    }

    public String getLangKey() {
        return langKey;
    }

    public Attribute langKey(String langKey) {
        this.langKey = langKey;
        return this;
    }

    public void setLangKey(String langKey) {
        this.langKey = langKey;
    }

    public Product getProduct() {
        return product;
    }

    public Attribute product(Product product) {
        this.product = product;
        return this;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public ProductSku getProductSku() {
        return productSku;
    }

    public Attribute productSku(ProductSku productSku) {
        this.productSku = productSku;
        return this;
    }

    public void setProductSku(ProductSku productSku) {
        this.productSku = productSku;
    }

    public Property getProperty() {
        return property;
    }

    public Attribute property(Property property) {
        this.property = property;
        return this;
    }

    public void setProperty(Property property) {
        this.property = property;
    }

    public Value getValue() {
        return value;
    }

    public Attribute value(Value value) {
        this.value = value;
        return this;
    }

    public void setValue(Value value) {
        this.value = value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Attribute attribute = (Attribute) o;
        if (attribute.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), attribute.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "Attribute{" +
            "id=" + getId() +
            ", skuPro='" + isSkuPro() + "'" +
            ", displayOrder='" + getDisplayOrder() + "'" +
            ", langKey='" + getLangKey() + "'" +
            "}";
    }
}
